/*
 * Example taken from resources.
 * Original from Prof. Waters
 */

import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;

import edu.gatech.coc.betameisters.main.DoctorsOffice;


/**
 * This class handles a client's connection and messages
 * It uses a simple text-based protocol
 *
 * @author Peter
 * @version 1.0
 */
public class ClientHandler implements Runnable {
    /** the socket for the client */
    private final Socket mySocket;

    /**
     * Creates a new ClientMessageHandler object.
     *
     * @param sock the socket made by the accept
     */
    public ClientHandler(final Socket sock) {
        mySocket = sock;
    }

    /**
     * Overidden Method
     *
     * @see java.lang.Runnable#run()
     */
    public void run() {
        System.out.println("Connection from "
            + mySocket.getInetAddress().getHostName());

        boolean notDone = true;

        try {
            //we loop here 
            while (notDone) {
                System.err.println("Got server message");
                DoctorsOffice office = new DoctorsOffice();
                mySocket.close(); // $codepro.audit.disable closeInFinally
                notDone = false;
                System.out.println("Connection Closed");
                }
        } catch (final SocketException se) { // $codepro.audit.disable logExceptions
            System.err.println("Detected Client Disconnect");
        } catch (final IOException e) { // $codepro.audit.disable logExceptions
            System.err.println(
                "Error in client handler, could not establish streams or "
                 +  " there was a disconnect");
        }
    }
    
    /**
     * Overrides toString method
     * @return returns the client status
     */
    public String toString(){
    	return "";
    }
}
